﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using GrayParrot.Web.Controls;
using GrayParrot.Core.Filters;
using FimetContoDeposito.DAL;
using FimetContoDeposito.BLL.Objects;

namespace FimetContoDeposito.BLL.ResultSets
{
    public class MagazziniResultSet : ResultSet<FCD_Magazzini>
	{
        public MagazziniResultSet(DTParameters param, IQueryable<FCD_Magazzini> result)
            : base(param, result)
        {
        }

        public override Expression<Func<FCD_Magazzini, bool>> ApplyGeneralFilter(string searchPattern)
        {
            var predicate = PredicateBuilder.False<FCD_Magazzini>();

            if (!string.IsNullOrWhiteSpace(searchPattern))
            {
                predicate = predicate.Or(im => im.Nome != null && im.Nome.ToString().Contains(searchPattern));
                predicate = predicate.Or(im => im.Note != null && im.Note.ToString().Contains(searchPattern));
                predicate = predicate.Or(im => im.DataCreazione != null && im.DataCreazione.ToString().Contains(searchPattern));
            }

            return predicate;
        }

        public override Expression<Func<FCD_Magazzini, bool>> ApplyGeneralColumnsFilter(List<string> columnSearch)
        {
            var predicate = PredicateBuilder.True<FCD_Magazzini>();

            string m_nome = columnSearch[ColumnIndex];
            string m_dataCreazione = columnSearch[ColumnIndex];
            string m_customer = columnSearch[ColumnIndex];
            string m_TipologiaDiUso = columnSearch[ColumnIndex];
            string m_UnitaDiMisura = columnSearch[ColumnIndex];


            //if (!string.IsNullOrWhiteSpace(m_descrizione))
            //{
            //    predicate = predicate.And(im => im.Descrizione.Equals(m_descrizione, StringComparison.InvariantCultureIgnoreCase));
            //}

            //if (!string.IsNullOrWhiteSpace(m_tipologiaArticolo))
            //{
            //    predicate = predicate.And(im => im.DescrTipologia == m_tipologiaArticolo);
            //}

            //if (!string.IsNullOrWhiteSpace(m_UnitaDiMisura))
            //{
            //    predicate = predicate.And(im => im.DescrUnitaDiMisura == m_UnitaDiMisura);
            //}

            return predicate;
        }
	}
}
